package com.rkc.controller;


import com.rkc.request.LockProductRequest;
import com.rkc.service.ProductService;
import com.rkc.utils.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 冉堃赤
 * @since 2021-10-28
 */
@Api("商品模块")
@RestController
@RequestMapping("/api/product/v1")
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping("page")
    @ApiOperation("分页查询列表")
    public JsonData pageProductList(@ApiParam("当前页") @RequestParam(value = "page", defaultValue = "1", required = false) int page
            , @ApiParam("每页大小") @RequestParam(value = "size", defaultValue = "10", required = false) int size) {
        return JsonData.buildSuccess(productService.page(page, size));
    }

    @GetMapping("detail/{product_id}")
    @ApiOperation("商品详情")
    public JsonData detail(@ApiParam(value = "商品id", required = true) @PathVariable("product_id") long productId) {
        return JsonData.buildSuccess(productService.detailById(productId));
    }

    @ApiOperation("商品库存锁定")
    @PostMapping("lock_products")
    public JsonData lockProducts(@ApiParam("商品库存锁定") @RequestBody LockProductRequest lockProductRequest) {
        return productService.lockProductStock(lockProductRequest);
    }
}

